#include "gameManager.h"

//test
#include "mainScreen/mainScreenLogic.h"

GameManager::GameManager()
	: m_pRootLayer(NULL)
{

}

GameManager::~GameManager()
{
}

GameManager* GameManager::createWithPhysics()
{
	GameManager *ret = new (std::nothrow) GameManager();
	if (ret && ret->initWithPhysics())
	{
		ret->autorelease();
		return ret;
	}
	else
	{
		CC_SAFE_DELETE(ret);
		return nullptr;
	}
}

GameManager* GameManager::getInstance()
{
	static GameManager* s_instance = GameManager::createWithPhysics();
	return s_instance;
}

void GameManager::physicsDebug(bool open)
{
	getPhysicsWorld()->setDebugDrawMask(open ? cocos2d::PhysicsWorld::DEBUGDRAW_ALL : cocos2d::PhysicsWorld::DEBUGDRAW_NONE);
}

void GameManager::replaceRootLayer(cocos2d::Layer *layer)
{
	if (NULL != m_pRootLayer)
	{
		m_pRootLayer->removeFromParent();
		m_pRootLayer = NULL;
	}

	m_pRootLayer = layer;

	//test
	layer = MainScreenLogic::create();
	addChild(layer);
}